Imports Clo = Enhancements.Core.Logging
Imports Gen = System.Collections.Generic
Imports Glo = System.Globalization
Imports Ref = System.Reflection
Imports Sys = System
Imports Val = Enhancements.Basic.Expressions.Values

Namespace Enhancements.Basic.Expressions
    <Serializable(), DebuggerStepThrough()> _
    Friend NotInheritable Class ___Texts

        Private Sub New()
        End Sub

        Friend Shared ReadOnly Property ComparisonMethod() As StringComparison
            Get
                Return StringComparison.InvariantCultureIgnoreCase
            End Get
        End Property

        Private Shared __StandardLetters() As System.String = Nothing
        Private Shared Function __StandardLettersGet() As System.String()
            If __StandardLetters.IsNull("__StandardLetters", False) Then
                Dim _standardLettersList As Gen.List(Of System.String) = New Gen.List(Of System.String)()
                _standardLettersList.AddRange(New System.String() {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"})
                _standardLettersList.AddRange(New System.String() {ToUpper("a"), ToUpper("b"), ToUpper("c"), ToUpper("d"), ToUpper("e"), ToUpper("f"), ToUpper("g"), ToUpper("h"), ToUpper("i"), ToUpper("j"), ToUpper("k"), ToUpper("l"), ToUpper("m"), ToUpper("n"), ToUpper("o"), ToUpper("p"), ToUpper("q"), ToUpper("r"), ToUpper("s"), ToUpper("t"), ToUpper("u"), ToUpper("v"), ToUpper("w"), ToUpper("x"), ToUpper("y"), ToUpper("z")})
                __StandardLetters = _standardLettersList.ToArray()
            End If

            Return __StandardLetters
        End Function

        Private Shared __StandardDigits() As System.String = Nothing
        Private Shared Function __StandardDigitsGet() As System.String()
            If __StandardDigits.IsNull("__StandardDigits", False) Then
                Dim _standardDigitsList As Gen.List(Of System.String) = New Gen.List(Of System.String)()
                _standardDigitsList.AddRange(New System.String() {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"})
                _standardDigitsList.AddRange(New System.String() {ToUpper("0"), ToUpper("1"), ToUpper("2"), ToUpper("3"), ToUpper("4"), ToUpper("5"), ToUpper("6"), ToUpper("7"), ToUpper("8"), ToUpper("9")})
                __StandardDigits = _standardDigitsList.ToArray()
            End If

            Return __StandardDigits
        End Function

        Friend Shared Function StartsWith(ByVal _stringToBeSearched As System.String, ByVal _stringToSearch As System.String) As System.Boolean
            Dim _returnValue As System.Boolean = False
            If Assert.IsNullNot(_stringToBeSearched, "_stringToBeSearched", False) AndAlso Assert.IsNullNot(_stringToSearch, "_stringToSearch", False) Then
                If Assert.IsEmptyNot(_stringToBeSearched, "_stringToBeSearched", False) AndAlso Assert.IsEmptyNot(_stringToSearch, "_stringToSearch", False) Then
                    If _stringToBeSearched.StartsWith(_stringToSearch, ComparisonMethod) Then
                        _returnValue = True
                    End If
                End If
            End If

            Return _returnValue
        End Function

        Friend Shared Function StartsWithStandardLetter(ByVal _stringToBeSearched As System.String) As System.Boolean
            Dim _returnValue As System.Boolean = False
            If Assert.IsNullNot(_stringToBeSearched, "_stringToBeSearched", False) Then
                If Assert.IsEmptyNot(_stringToBeSearched, "_stringToBeSearched", False) Then
                    For Each _standardLetter As System.String In __StandardLettersGet()
                        If StartsWith(_stringToBeSearched, _standardLetter) Then
                            _returnValue = True
                            Exit For
                        End If
                    Next _standardLetter
                End If
            End If

            Return _returnValue
        End Function

        Friend Shared Function StartsWithStandardDigit(ByVal _stringToBeSearched As System.String) As System.Boolean
            Dim _returnValue As System.Boolean = False
            If Assert.IsNullNot(_stringToBeSearched, "_stringToBeSearched", False) Then
                If Assert.IsEmptyNot(_stringToBeSearched, "_stringToBeSearched", False) Then
                    For Each _standardDigit As System.String In __StandardDigitsGet()
                        If StartsWith(_stringToBeSearched, _standardDigit) Then
                            _returnValue = True
                            Exit For
                        End If
                    Next _standardDigit
                End If
            End If

            Return _returnValue
        End Function

        Friend Shared Function StartsWithUnderscore(ByVal _stringToBeSearched As System.String) As System.Boolean
            Dim _returnValue As System.Boolean = False
            If Assert.IsNullNot(_stringToBeSearched, "_stringToBeSearched", False) Then
                If Assert.IsEmptyNot(_stringToBeSearched, "_stringToBeSearched", False) Then
                    If StartsWith(_stringToBeSearched, "_") Then
                        _returnValue = True
                    End If
                End If
            End If

            Return _returnValue
        End Function

        Friend Shared Function IsStandardLetter(ByVal _character As System.Char) As System.Boolean
            Dim _returnValue As System.Boolean = __StandardLettersGet().Contains(_character)

            Return _returnValue
        End Function

        Friend Shared Function IsStandardDigit(ByVal _character As System.Char) As System.Boolean
            Dim _returnValue As System.Boolean = __StandardDigitsGet().Contains(_character)

            Return _returnValue
        End Function

        Friend Shared Function IsUnderscore(ByVal _character As System.Char) As System.Boolean
            Dim _returnValue As System.Boolean = False
            If ToUpper(_character) = ToUpper("_") Then
                _returnValue = True
            End If

            Return _returnValue
        End Function

        Friend Shared Function ContainsOnlyStandardLettersAndStandardDigitsAndUnderscores(ByVal _stringToBeSearched As System.String) As System.Boolean
            Dim _returnValue As System.Boolean = True
            If Assert.IsNull(_stringToBeSearched, "_stringToBeSearched", False) Then
                _returnValue = False
            Else
                If Assert.IsEmpty(_stringToBeSearched, "_stringToBeSearched", False) Then
                    _returnValue = False
                Else
                    _returnValue = _stringToBeSearched.Count(Function(_character) Not (IsStandardLetter(_character) Or IsStandardDigit(_character) Or IsUnderscore(_character))) = 0
                End If
            End If

            Return _returnValue
        End Function

        Friend Shared Function ContainsAtLeastOneStandardLetterOrStandardDigit(ByVal _stringToBeSearched As System.String) As System.Boolean
            Dim _returnValue As System.Boolean = False
            If Assert.IsNullNot(_stringToBeSearched, "_stringToBeSearched", False) Then
                _returnValue = _stringToBeSearched.Count(Function(_character) IsStandardLetter(_character) Or IsStandardDigit(_character)) >= 1
            End If

            Return _returnValue
        End Function

        Friend Shared Function EndsWith(ByVal _stringToBeSearched As System.String, ByVal _stringToSearch As System.String) As System.Boolean
            Dim _returnValue As System.Boolean = False
            If Assert.IsNullNot(_stringToBeSearched, "_stringToBeSearched", False) AndAlso Assert.IsNullNot(_stringToSearch, "_stringToSearch", False) Then
                If Assert.IsEmptyNot(_stringToBeSearched, "_stringToBeSearched", False) AndAlso Assert.IsEmptyNot(_stringToSearch, "_stringToSearch", False) Then
                    If _stringToBeSearched.EndsWith(_stringToSearch, ComparisonMethod) Then
                        _returnValue = True
                    End If
                End If
            End If

            Return _returnValue
        End Function

        Friend Shared Function IndexOf(ByVal _stringToBeSearched As System.String, ByVal _stringToSearch As System.String, ByVal _beginIndex As Sys.Int32) As System.Int32
            Dim _returnValue As System.Int32 = -1
            If Assert.IsNullNot(_stringToBeSearched, "_stringToBeSearched", False) AndAlso Assert.IsNullNot(_stringToSearch, "_stringToSearch", False) Then
                If Assert.IsEmptyNot(_stringToBeSearched, "_stringToBeSearched", False) AndAlso Assert.IsEmptyNot(_stringToSearch, "_stringToSearch", False) Then
                    If Assert.IsInRange(_beginIndex, "_beginIndex", 0, _stringToBeSearched.Length - 1, False) Then
                        _returnValue = _stringToBeSearched.IndexOf(_stringToSearch, _beginIndex, ComparisonMethod)
                    End If
                End If
            End If

            Return _returnValue
        End Function

        Friend Shared Function AreEqual(ByVal _first As System.Char, ByVal _second As System.Char) As System.Boolean
            Dim _firstString As System.String = _first
            Dim _secondString As System.String = _second
            Dim _returnValue As System.Boolean = AreEqual(_firstString, _secondString)

            Return _returnValue
        End Function

        Friend Shared Function AreEqual(ByVal _first As System.String, ByVal _second As System.String) As System.Boolean
            Dim _returnValue As System.Boolean = False
            If _first.IsNull("_first", False) AndAlso _second.IsNull("_second", False) Then
                _returnValue = True
            Else
                If _first.IsNullNot("_first", False) AndAlso _second.IsNullNot("_second", False) Then
                    If Sys.String.Compare(_first, _second, ComparisonMethod) = 0 Then
                        _returnValue = True
                    End If
                End If
            End If

            Return _returnValue
        End Function

        Friend Shared Function ToUpper(ByVal _string As System.String) As System.String
            Dim _returnValue As System.String = Nothing
            If _string.IsNull("_string", False) Then
                _returnValue = Nothing
            Else
                _returnValue = _string.ToUpperInvariant()
            End If

            Return _returnValue
        End Function

        Friend Shared Function ToUpper(ByVal _integer As Sys.Int64) As System.String
            Dim _returnValue As System.String = ToUpper(_integer.ToString("G", Glo.CultureInfo.InvariantCulture))

            Return _returnValue
        End Function

        Friend Shared Function ToUpper(ByVal _decimal As System.Decimal) As System.String
            Dim _returnValue As System.String = ToUpper(_decimal.ToString("G", Glo.CultureInfo.InvariantCulture) + Val.Decimal.TypeSpecifierRepresentation)

            Return _returnValue
        End Function

    End Class
End Namespace
